package com.xyhuo.leetcode;

import java.util.ArrayList;
import java.util.List;

public class OrderedStream {

    int ptr = 0;

    String[] list;

    public OrderedStream(int n) {
        list = new String[n];
    }

    public List<String> insert(int idKey, String value) {
        list[idKey - 1] = value;
        List<String> result = new ArrayList<>();
        while (ptr < list.length && list[ptr] != null) {
            result.add(list[ptr]);
            ptr++;
        }
        return result;
    }

    public static void main(String[] args) {
        OrderedStream os = new OrderedStream(5);
        List<String> ccc = os.insert(3, "ccc");

        List<String> aaa = os.insert(1, "aaa");
        List<String> bbb = os.insert(2, "bbb");
        List<String> eee = os.insert(5, "eee");
        List<String> ddd = os.insert(4, "ddd");


    }
}
